import java.io.*;
import java.util.*;

/* ObjectReader reads a file that contains a list of objects, 
 * and returns them
 */

public class ObjectReader {
	
	// Constructor
	public ObjectReader() {}
	
	// Reads the file located at 'path' and returns the list of CrawlResults
	public List<CrawlResult> readCrawlResult(String path){
		List<CrawlResult> crList = new ArrayList<CrawlResult>();
	    ObjectInputStream ois = null;
		
		try {
			  ois = new ObjectInputStream(new FileInputStream(path));
			  CrawlResult obj = null;
		      while( (obj = (CrawlResult)ois.readObject()) != null) {
		    		  crList.add(obj);
		      }
		      		      
		} 
		catch(EOFException e) {
//			System.out.println("EOF Reached");
		}
		catch(Exception e) {
			System.err.println("ObjectReader Exception");
			e.printStackTrace();
		} 
		finally {
			try {
				if (ois != null) {
					ois.close();
				}
			} catch (Exception e) {}
		}
		return crList;
	}
}
